-- Viral Resistance - T-Engine 4 Module
-- Copyright (C) 2010 Mikolai Fajer
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
--
-- Mikolai Fajer "yufra"
-- mfajer@gmail.com

newEntity{
	define_as = "UP",
	name = "previous level",
	display = '<', color_r=255, color_g=255, color_b=0, back_color=colors.DARK_GREY,
	image = "terrain/floor_office.png",
	add_displays = {
		engine.Entity.new{
			display_on_seen = true,
			display_on_remember = true,
			image = "terrain/stairs_up.png",
		},
	},
	notice = true,
	always_remember = true,
	change_level = 1,
	tooltip = "Stairs leading upwards.",
}

newEntity{
	define_as = "DOWN",
	name = "next level",
	display = '>', color_r=255, color_g=255, color_b=0, back_color=colors.DARK_GREY,
	image = "terrain/floor_office.png",
	add_displays = {
		engine.Entity.new{
			display_on_seen = true,
			display_on_remember = true,
			image = "terrain/stairs_down.png",
		},
	},
	notice = true,
	always_remember = true,
	change_level = -1,
	tooltip = "Stairs leading downwards.",
}

newEntity{
	define_as = "FLOOR",
	name = "floor", image = "terrain/floor_office.png",
	display = '.',
	color = colors.GREY,
	back_color = colors.GREY,
}

newEntity{
	define_as = "WALL",
	name = "wall",
	display = '#',
	color = colors.GREY,
	color_br=250, color_bg=250, color_bb=250,
	image = "terrain/wall_hospital.png",
	always_remember = true,
	does_block_move = true,
	can_pass = {pass_wall=1},
	block_sight = true,
	air_level = -20,
	dig = "FLOOR",
}

newEntity{
	define_as = "DOOR",
	name = "door",
	display = '+', color_r=238, color_g=33, color_b=12,
	color_br=235, color_bg=126, color_bb=37,
	notice = true,
	door_opened = "DOOR_OPENED",
	door_locked = "DOOR_LOCKED",
	block_sight = true,
	dig = "DOOR_OPENED",
	tooltip = "A closed door with a window in it.",
}

newEntity{
	define_as = "DOOR_OPENED",
	name = "open door",
	display = "'", color_r=238, color_g=33, color_b=12, back_color=colors.DARK_GREY,
	door_closed = "DOOR",
	door_locked = "DOOR_LOCKED",
	tooltip = "An open door.",
	close_countdown = 4,
	energy = { value=0, mod=1 },
	canAct = false,
	on_added = function(self, level, x, y)
		self.x = x
		self.y = y
		level:addEntity(self)
	end,
	act = function(self)
		-- Do basic actor stuff
		if not engine.Actor.act(self) then return end
		
		-- Shut the door?
		if game.level.map(self.x, self.y, engine.Map.ACTOR) or game.level.map(self.x, self.y, engine.Map.OBJECT) then
			self.close_countdown = 4
		else
			self.close_countdown = self.close_countdown - 1
		end
		if self.close_countdown <= 0 then
			game.level:removeEntity(self)
			game.level.map(self.x, self.y, engine.Map.TERRAIN, game.zone.grid_list[self.door_closed])
		end
		
		if not self.energy.used then self:useEnergy() end
		return true
	end,
	on_move = function(self, x, y, who)
		self.close_countdown = 4
	end,
	useEnergy = function(self, val)
		val = val or game.energy_to_act
		self.energy.value = self.energy.value - val
	end,
}

newEntity{ base = "DOOR",
	define_as = "DOOR_LOCKED",
	name = "locked door",
	color=colors.VIOLET,
	door_unlocked = "DOOR",
	door_opened = false,
	door_locked = false,
	does_block_move = true,
	tooltip = "A locked door with a window in it.",
}

newEntity{ base = "DOOR",
	define_as = "WOODEN_DOOR",
	tooltip = "A closed wooden door.",
	door_opened = "WOODEN_OPEN",
	door_locked = "WOODEN_LOCKED",
	image = "terrain/wooden_door_closed.png",
}

newEntity{ base = "DOOR_OPENED",
	define_as = "WOODEN_OPEN",
	tooltip = "An open elevator door.",
	door_closed = "WOODEN_DOOR",
	door_locked = "WOODEN_LOCKED",
	image = "terrain/floor_office.png",
	add_displays = {
		engine.Entity.new{
			display_on_seen = true,
			display_on_remember = true,
			image = "terrain/wooden_door_opened.png",
		},
	},
}

newEntity{ base = "DOOR_LOCKED",
	define_as = "WOODEN_LOCKED",
	tooltip = "A locked wooden door.",
	door_unlocked = "WOODEN_DOOR",
	image = "terrain/wooden_door_closed.png",
}

newEntity{ base = "DOOR",
	define_as = "ELEVATOR_DOOR",
	tooltip = "A closed elevator door.",
	door_opened = "ELEVATOR_OPEN",
	door_locked = "ELEVATOR_LOCKED",
	image = "terrain/iron_door_closed.png",
}

newEntity{ base = "DOOR_OPENED",
	define_as = "ELEVATOR_OPEN",
	tooltip = "An open elevator door.",
	door_closed = "ELEVATOR_DOOR",
	door_locked = "ELEVATOR_LOCKED",
	image = "terrain/floor_office.png",
	add_displays = {
		engine.Entity.new{
			display_on_seen = true,
			display_on_remember = true,
			image = "terrain/iron_door_opened.png",
		},
	},
}

newEntity{ base = "DOOR_LOCKED",
	define_as = "ELEVATOR_LOCKED",
	tooltip = "An unresponsive elevator door.",
	door_unlocked = "ELEVATOR_DOOR",
	image = "terrain/iron_door_closed.png",
}

newEntity{ base = "DOOR",
	define_as = "WINDOWED_DOOR",
	image = "terrain/hospital_door_closed.png",
	tooltip = "A closed door with a window in it.",
	display = 'o',
	door_opened = "WINDOWED_DOOR_OPENED",
	door_locked = "WINDOWED_DOOR_LOCKED",
	block_sight = false,
}

newEntity{ base = "DOOR_OPENED",
	define_as = "WINDOWED_DOOR_OPENED",
	image = "terrain/floor_office.png",
	add_displays = {
		engine.Entity.new{
			display_on_seen = true,
			display_on_remember = true,
			image = "terrain/hospital_door_opened.png",
		},
	},
	tooltip = "An open door.",
	door_closed = "WINDOWED_DOOR",
	door_locked = "WINDOWED_DOOR_LOCKED",
}

newEntity{ base = "DOOR_LOCKED",
	define_as = "WINDOWED_DOOR_LOCKED",
	image = "terrain/hospital_door_closed.png",
	tooltip = "An locked door with a window in it.",
	display = 'o',
	door_unlocked= "WINDOWED_DOOR",
	block_sight = false,
}

newEntity{
	define_as = "DESK",
	name = "desk",
	display = '=', color_r=238, color_g=154, color_b=77, back_color=colors.GREEN,
	notice = true,
	block_sight = false,
	does_block_move = true,
	dig = "FLOOR",
	tooltip = "A desk.",
	climbable = {difficulty=0, speed_mod=0.75},
}

newEntity{
	define_as = "BED",
	name = "bed",
	display = '#', color_r=31, color_g=136, color_b=145,
	color_br=247, color_bg=239, color_bb=37,
	notice = true,
	block_sight = false,
	does_block_move = true,
	dig = "FLOOR",
	tooltip = "A bed.",
	climbable = {difficulty=0, speed_mod=1.0},
}

newEntity{
	define_as = "OPERATING_TABLE",
	name = "operating table",
	display = '#', color_r=176, color_g=196, color_b=222,
	color_br=70, color_bg=130, color_bb=180,
	notice = true,
	block_sight = false,
	does_block_move = true,
	dig = "FLOOR",
	tooltip = "An operating table.",
	climbable = {difficulty=0, speed_mod=0.75},
}

newEntity{
	define_as = "WINDOW",
	name = "window",
	display = 'o', color=colors.ANTIQUE_WHITE,
	color_br=250, color_bg=250, color_bb=250,
	image = "terrain/wall_hospital.png",
	add_displays = {
		engine.Entity.new{
			display_on_seen = true,
			display_on_remember = true,
			image = "terrain/window_closed.png",
		},
	},
	notice = true,
	block_sight = false,
	does_block_move = true,
	dig = "FLOOR",
	tooltip = "A window.",
}

newEntity{
	define_as = "BARRIER",
	name = "barrier",
	display = '=',
	color=colors.PURPLE,
	back_color=colors.GREEN,
	notice = true,
	block_sight = false,
	does_block_move = true,
	dig = "FLOOR",
	tooltip = "An overturned desk.",
}